/*
 * @Description: RegexUtil
 * @Author: zhaokun
 * @Date: 2022-01-07 15:26:38
 * @LastEditTime: 2022-01-10 17:25:21
 * @FilePath: \user\common\nwRegex.go
 */
package common

import "regexp"

type RegexUtil interface {
	IsEmail(str string) bool
	IsPhone(str string) bool
}

type nwRegexUtil struct {
}

func NewNwRegexUtil() *nwRegexUtil {
	return &nwRegexUtil{}
}

/**
 * @description: IsEmail
 * @param {string} str
 * @return bool
 */
func (regexUtil *nwRegexUtil) IsEmail(str string) bool {
	result, _ := regexp.MatchString("^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$", str)
	if result {
		return true
	} else {
		return false
	}
}

/**
 * @description: IsPhone
 * @param {string} str
 * @return bool
 */
func (regexUtil *nwRegexUtil) IsPhone(str string) bool {
	result, _ := regexp.MatchString("^1[0-9]{10}$", str)
	if result {
		return true
	} else {
		return false
	}
}

/**
 * @description: IsIp
 * @param {string} str
 * @return bool
 */
func (regexUtil *nwRegexUtil) IsIp(str string) bool {
	result, _ := regexp.MatchString("[\\d]+\\.[\\d]+\\.[\\d]+\\.[\\d]+", str)
	if result {
		return true
	} else {
		return false
	}
}
